package ua.com.fesvlast.hotel.model.commands;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ua.com.fesvlast.hotel.controller.managers.ConfigurationManager;
import ua.com.fesvlast.hotel.controller.managers.MessageManager;
import ua.com.fesvlast.hotel.model.dao.DAOFactory;
import ua.com.fesvlast.hotel.model.enteties.HotelRooms;

public class PicturesCommand implements ICommand {

	@Override
	public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			
		String page =null;
		
		List<HotelRooms> rooms=null;
		try {
			rooms = DAOFactory.getHotelsRoomsDAO().getListRooms();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if(rooms !=null){
			request.setAttribute("rooms", rooms);
			page=ConfigurationManager.getInstance().getProperty(ConfigurationManager.HOTEL_ROOMS_PAGE);
		}else{
			request.setAttribute("errorMessage", MessageManager.getInstance().getProperty(
					MessageManager.LOGIN_ERROR_MESSAGE));
			
			page=ConfigurationManager.getInstance().getProperty(
					ConfigurationManager.ERROR_PAGE_PATH);
		}
		return page;
	}

}
